import 'package:flutter/material.dart';
import '../../config/app_routes.dart';
import '../../config/app_theme.dart';
import '../../entity/game.dart';

class LibraryGameCard extends StatelessWidget {
  final Game game;

  const LibraryGameCard({super.key, required this.game});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        //点击时导航到详情页
        Navigator.of(context).pushNamed(
          gameDetail_page,
          arguments: game,
        );
      },
      child: Card(
        clipBehavior: Clip.antiAlias,
        elevation: 2.0, //阴影
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch, //让子项填满宽度
          children: [
            //使用Expanded让图片填充所有可用的垂直空间
            Expanded(
              child: Image.asset(
                game.coverImage,
                fit: BoxFit.cover,
                errorBuilder: (context, error, stackTrace) {
                  return const Center(child: Icon(Icons.broken_image));
                },
              ),
            ),
            //游戏标题
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                game.name,
                style: const TextStyle(
                  fontSize: 14,
                  fontWeight: titleFontWeight,
                ),
                maxLines: 1,
                overflow: TextOverflow.ellipsis, //超出部分显示省略号
              ),
            ),
          ],
        ),
      ),
    );
  }
}